package com.attilax.util;

import java.awt.Color;
import java.awt.Point;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

import com.google.common.collect.Lists;

public class LayerCater {

	public LayerCater(int maxValue) {
		this.maxV = maxValue;
		// return this;
	}

	public LayerCater() {
		this.maxV = 255;
	}

	public static void main(String[] args) {
		System.out.println(AtiJson.toJson(new LayerCater().iniLayers_groupByGray(5, 255)));
	}

	private List<Layer> Buker_list;

	public List<Layer> iniLayers_groupBy(int layersCnt, int max) {
		List<Layer> li = Lists.newArrayList();
		int span = max / layersCnt;
		for (int i = 0; i < layersCnt; i++) {

			Layer Layer1 = new Layer();
			Layer1.min = i * (span);
			Layer1.max = (i + 1) * span - 1;
			// if(bk.max>max)
			// bk.max=max;
			if (i == layersCnt - 1) // last
				Layer1.max = max;
			li.add(Layer1);
		}
		this.Buker_list = li;
		return li;
	}

	List<Color> matrix_li_clr_4dbg = Lists.newArrayList();// for dbg
	private int maxV;

	public void clrAllBukesColors() {
		for (Layer buker : Buker_list) {

			buker.clrAllColors();
		}

	}

	public List<Layer> iniBukersByHsvSplit(int clrNums, int max) {
		List<Layer> li = Lists.newArrayList();
		int span = max / clrNums;
		for (int i = 0; i < clrNums; i++) {

			Layer bk = new Layer();
			bk.min = i * (span);
			bk.max = (i + 1) * span - 1;
			// if(bk.max>max)
			// bk.max=max;
			if (i == clrNums - 1) // last
				bk.max = max;
			li.add(bk);
		}
		this.Buker_list = li;
		return li;
	}

	public LayerCater iniLayers(int maxValue) {
		this.maxV = maxValue;
		return this;
	}

	public LayerCater groupByGrayRang(int grayLevDeep) {
		int clrNums = grayLevDeep;
		int max = this.maxV;
		List<Layer> li = Lists.newArrayList();
		int span = max / clrNums;
		for (int i = 0; i < clrNums; i++) {

			Layer bk = new Layer();
			bk.min = i * (span);
			bk.max = (i + 1) * span - 1;
			// if(bk.max>max)
			// bk.max=max;
			if (i == clrNums - 1) // last
				bk.max = max;
			li.add(bk);
		}
		this.Buker_list = li;
		return this;
		// return null;
	}

	public LayerCater insertInto_Layers() {
		// TODO Auto-generated method stub
		return this;
	}

	public int getLayerIndex(int abc) {
		int n = 1;
		for (Layer layer : Buker_list) {
			if (abc >= layer.min && abc < layer.max)
				return n;
			n++;
		}
		return -1;
	}

}
